home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
mint
/
mint110s.zoo
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-11
|
41KB
|
1,548 lines
/*
Copyright 1990,1991,1992 Eric R. Smith.
Copyright 1992,1993,1994 Atari Corporation.
All rights reserved.
*/
#include "mint.h"
#include "version.h"
#include "cookie.h"
#include "xbra.h"
/* the kernel's stack size */
#define STACK 8*1024L
/* if the user is holding down the magic shift key, we ask before booting */
#define MAGIC_SHIFT 0x2 /* left shift */
/* magic number to show that we have captured the reset vector */
#define RES_MAGIC 0x31415926L
static void xbra_install P_((xbra_vec *, long, long ARGS_ON_STACK (*)()));
static void init_intr P_((void));
static long getmch P_((void));
static void do_line P_((char *));
static void do_file P_((int));
static void shutmedown P_((PROC *));
void shutdown P_((void));
static void doset P_((char *,char *));
static long ARGS_ON_STACK mint_criticerr P_((long));
static void ARGS_ON_STACK do_exec_os P_((register long basepage));
static int gem_active; /* 0 if AES has not started, nonzero otherwise */
#define EXEC_OS 0x4feL
static int check_for_gem P_((void));
static void run_auto_prgs P_((void));
#ifdef LATTICE
/*
* AGK: this is witchcraft to completely replace the startup code for
* Lattice; doing so saves around 10K on the final binary and pulls only
* long division & multitplication from the library (and not even those
* if you compile for native '030). The drawback of this code is it
* passes no environment or command line whatsoever. Since I always
* set MiNT options & environment in 'mint.cnf' this is not a personal
* downer, however at some point in the future we ought to have a kernel
* parseargs() like call which sets these things up.
*/
BASEPAGE *_base;
static void
start(BASEPAGE *bp)
{
long shrinklen;
_base = bp;
shrinklen = bp->p_tlen + bp->p_dlen + bp->p_blen + STACK + 0x100;
if (bp->p_lowtpa + shrinklen <= bp->p_hitpa) {
static char null[1] = {""};
static char *argv[2] = {null, NULL};
extern __builtin_putreg P_((int, long)); /* totally bogus */
__builtin_putreg(15, bp->p_lowtpa + shrinklen);
Mshrink((void *)bp->p_lowtpa, shrinklen);
main(1, argv);
}
Pterm(ENSMEM);
}
#endif
#if defined(__GNUC__) || defined(__MINT__)
long _stksize = STACK;
#ifndef PROFILING
#include <minimal.h>
#endif
#endif
int curs_off = 0; /* set if we should turn the cursor off when exiting */
int mint_errno = 0; /* error return from open and creat filesystem calls */
/*
* AGK: for proper co-processors we must consider saving their context.
* This variable when non-zero indicates that the BIOS considers a true
* coprocessor to be present. We use this variable in the context switch
* code to decide whether to attempt an FPU context save.
*/
short fpu = 0;
/*
* "mch" holds what kind of machine we are running on
*/
long mch = 0;
/*
* "screen_boundary+1" tells us how screens must be positioned
* (to a 256 byte boundary on STs, a 16 byte boundary on other
* machines; actually, 16 bytes is conservative, 4 is probably
* OK, but it doesn't hurt to be cautious). The +1 is because
* we're using this as a mask in the ROUND() macro in mem.h.
*/
int screen_boundary = 255;
/*
* variable holds processor type
*/
long mcpu = 0;
/*
* variable holds language preference
*/
int gl_lang = -1;
/*
* variable set if someone has already installed an flk cookie
*/
int flk = 0;
/*
* variable set to 1 if the _VDO cookie indicates Falcon style video
*/
int FalconVideo;
/* program to run at startup */
#ifdef MULTITOS
static int init_is_gem = 1; /* set to 1 if init_prg is GEM */
#else
static int init_is_gem = 0; /* set to 1 if init_prg is GEM */
#endif
static const char *init_prg = 0;
/* note: init_tail is also used as a temporary stack for resets in
* intr.spp
*/
char init_tail[256];
/* initial environment for that program */
static char *init_env = 0;
/* temporary pointer into that environment for setenv */
static char *env_ptr;
/* length of the environment */
static long env_len;
/* GEMDOS pointer to current basepage */
BASEPAGE **tosbp;
/* pointer to the BIOS keyboard shift variable */
extern char *kbshft; /* see bios.c */
/* version of TOS we're running over */
int tosvers;
/* structures for keyboard/MIDI interrupt vectors */
KBDVEC *syskey, oldkey;
xbra_vec old_ikbd; /* old ikbd vector */
/* values the user sees for the DOS, BIOS, and XBIOS vectors */
long save_dos, save_bios, save_xbios;
/* values for original system vectors */
xbra_vec old_dos, old_bios, old_xbios, old_timer, old_vbl, old_5ms;
xbra_vec old_criticerr;
xbra_vec old_execos;
long old_term;
xbra_vec old_resvec; /* old reset vector */
long old_resval; /* old reset validation */
#ifdef EXCEPTION_SIGS
/* bus error, address error, illegal instruction, etc. vectors */
xbra_vec old_bus, old_addr, old_ill, old_divzero, old_trace, old_priv;
xbra_vec old_linef, old_chk, old_trapv, old_mmuconf, old_format, old_cpv;
xbra_vec old_uninit, old_spurious, old_fpcp[7], old_pmmuill, old_pmmuacc;
#endif
/* BIOS disk vectors */
xbra_vec old_mediach, old_getbpb, old_rwabs;
/* BIOS drive map */
long olddrvs;
extern Func bios_tab[], dos_tab[];
/* kernel info that is passed to loaded file systems and device drivers */
struct kerinfo kernelinfo = {
MAJ_VERSION, MIN_VERSION,
DEFAULT_MODE, 0,
bios_tab, dos_tab,
changedrv,
Trace, Debug, ALERT, FATAL,
kmalloc, kfree, umalloc, ufree,
strnicmp, stricmp, strlwr, strupr, ksprintf,
ms_time, unixtim, dostim,
nap, sleep, wake, wakeselect,
denyshare, denylock, addtimeout, canceltimeout
};
/* table of processor frame sizes in _words_ (not used on MC68000) */
unsigned char framesizes[16] = {
/*0*/ 0, /* MC68010/M68020/M68030/M68040 short */
/*1*/ 0, /* M68020/M68030/M68040 throwaway */
/*2*/ 2, /* M68020/M68030/M68040 instruction error */
/*3*/ 2, /* M68040 floating point post instruction */
/*4*/ 3, /* MC68LC040/MC68EC040 unimplemented floating point instruction */
/*5*/ 0, /* NOTUSED */
/*6*/ 0, /* NOTUSED */
/*7*/ 26, /* M68040 access error */
/*8*/ 25, /* MC68010 long */
/*9*/ 6, /* M68020/M68030 mid instruction */
/*A*/ 12, /* M68020/M68030 short bus cycle */
/*B*/ 42, /* M68020/M68030 long bus cycle */
/*C*/ 8, /* CPU32 bus error */
/*D*/ 0, /* NOTUSED */
/*E*/ 0, /* NOTUSED */
/*F*/ 13 /* 68070 and 9xC1xx microcontroller address error */
};
/* TOS and MiNT cookie jars, respectively. See the comments and code
* after main() for further details
*/
COOKIE *oldcookie, *newcookie;
/*
* install a new vector for address "addr", using the XBRA protocol.
* must run in supervisor mode!
*/
static void
xbra_install(xv, addr, func)
xbra_vec *xv;
long addr;
long ARGS_ON_STACK (*func)();
{
xv->xbra_magic = XBRA_MAGIC;
xv->xbra_id = MINT_MAGIC;
xv->jump = JMP_OPCODE;
xv->this = func;
xv->next = *((struct xbra **)addr);
*((short **)addr) = &xv->jump;
}
/*
* MiNT critical error handler; all it does is to jump through
* the vector for the current process
*/
static long ARGS_ON_STACK
mint_criticerr(error)
long error; /* high word is error, low is drive */
{
return (*curproc->criticerr)(error);
}
/*
* if we are MultiTOS, and if we are running from the AUTO folder,
* then we grab the exec_os vector and use that to start GEM; that
* way programs that expect exec_os to act a certain way will still
* work.
* NOTE: we must use Pexec instead of p_exec here, because we will
* be running in a user context (that of process 1, not process 0)
*/
static void ARGS_ON_STACK
do_exec_os(basepage)
register long basepage;
{
register long r;
/* if the user didn't specify a startup program, jump to the ROM */
if (!init_prg) {
register void ARGS_ON_STACK (*f) P_((long));
f = (void ARGS_ON_STACK (*) P_((long))) old_execos.next;
(*f)(basepage);
Pterm0();
} else {
/* we have to set a7 to point to lower in our TPA; otherwise we would
* bus error right after the Mshrink call!
*/
setstack(basepage+500L);
#if defined(__TURBOC__) && !defined(__MINT__)
Mshrink(0, (void *